home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / bbsread / parserecent.br < prev    next >
Text File  |  1998-05-24  |  10KB  |  380 lines

  1. /*
  2. ** $VER: ParseRECENT.br 1.2 (6.9.97)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** See SortMail.guide for documentation
  6. **
  7. */
  8.  
  9. options results
  10. options failat 31
  11.  
  12. parse arg arguments
  13.  
  14. /*
  15. ** Initialize some variables
  16. */
  17.  
  18. version  = subword(sourceline(2), 4, 1)
  19.  
  20. template = 'SYSTEM/A,CONFERENCE/A,MSGNO/A/N,CHECKDUPES/S,DONTADD/S,NOSTATS/S'
  21. args.CHECKDUPES = 0; args.DONTADD = 0; args.NOSTATS = 0
  22.  
  23. globals  = 'newmsg. logcount head. version BBSREAD.LASTERROR myerr returned globals'
  24.  
  25. curline = 1; res = 0; logcount = 0; returned = 0
  26.  
  27. /*
  28. ** Find/open BBSREAD ARexx port
  29. */
  30.  
  31. if ~(show('P', 'BBSREAD')) then do
  32.     address(command)
  33.     'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  34.     if exists('SYS:RexxC/WaitForPort') then 'SYS:RexxC/WaitForPort BBSREAD'
  35.     else 'WaitForPort BBSREAD'
  36.     if (rc = 5) then do; say 'Could not open BBSREAD''s ARexx port.'; exit(30); end
  37.     if (rc ~= 0) then do; say 'Could not find SYS:Rexxc/WaitForPort.'; exit(30); end
  38.     end
  39.  
  40. /*
  41. ** Give template if arguments = '?'
  42. */
  43.  
  44. if (arguments = '?') then do
  45.     say 'Usage: 'template
  46.     say 'ParseRECENT.br is an external script for SortMail.'
  47.     exit(5)
  48.     end
  49.  
  50. address(bbsread)
  51. 'READARGS TEMPLATE "'template'" STEM 'args' CMDLINE 'arguments
  52. if (rc ~= 0) then do
  53.     say BBSREAD.LASTERROR
  54.     say 'Template: 'template
  55.     say 'ParseRECENT.br is an external script for SortMail.'
  56.     exit(5)
  57.     end
  58.  
  59. /*
  60. ** Utilize BBSRead's copyback buffer
  61. */
  62.  
  63. 'BUFMODE COPYBACK'
  64.  
  65. /*
  66. ** Read message's header and text stems
  67. */
  68.  
  69. 'READBRMESSAGE "'args.SYSTEM'" "'args.CONFERENCE'" 'args.MSGNO' HEADSTEM 'head' DATASTEM 'data' TEXTSTEM 'text
  70. if (rc ~= 0) then signal error
  71.  
  72. /*
  73. ** Get system data and compensate for a bug in bbsread on OS2.x systems
  74. */
  75.  
  76. 'GETBBSDATA "'args.SYSTEM'" STEM 'bbsdata
  77. if (rc ~= 0) then signal error
  78.  
  79. if (right(bbsdata.BBSPATH, 1) ~= ':') & (right(bbsdata.BBSPATH, 1) ~= '/') then bbsdata.BBSPATH = bbsdata.BBSPATH || '/'
  80.  
  81. /*
  82. ** Exit if it doesn't start with "|" (then it's probably not a RECENT msg)
  83. */
  84.  
  85. if (left(text.TEXT.curline, 1) ~= '|') then do
  86.     myerr = 'Not an AmiNet RECENT message.'; rc = 5; signal error
  87.     end
  88.  
  89. /*
  90. ** Read exclude file
  91. */
  92.  
  93. openexcl = open(ef, bbsdata.BBSPATH || 'SortMail.excl', 'R')
  94. if (openexcl) then do
  95.     cnt = 0
  96.     do until eof(ef)
  97.         entry = readln(ef)
  98.         if (entry ~= '') then do; cnt = cnt + 1; excldir.cnt = entry; end
  99.         end
  100.     excldir.count = cnt
  101.     call close(ef)
  102.     end
  103.  
  104. /*
  105. ** Skip all lines beginning with "|"
  106. */
  107.  
  108. do while(left(text.TEXT.curline, 1) = '|'); curline = curline + 1; end
  109.  
  110. /*
  111. ** See if NewFiles.txt is old by checking date. If lastadd is not set
  112. ** or was set more than 30 minutes ago, then it is old
  113. */
  114.  
  115. lastadd = getclip('SM_LastAdd')
  116.  
  117. if (lastadd ~= '') & (lastadd >= ((date('I') * 24 * 60) + (time('M') - 30))) then delnf = 0
  118. else delnf = 1
  119.  
  120. /*
  121. ** Exit if there are no new files
  122. */
  123.  
  124. if (curline >= text.TEXT.COUNT) then do
  125.     if (delnf) & (exists(bbsdata.BBSPATH || 'Newfiles.txt')) then do
  126.         address(command)
  127.         'Delete "' || bbsdata.BBSPATH || 'Newfiles.txt" QUIET'
  128.         if (rc ~= 0) then do; myerr = 'Could not delete Newfiles.txt.'; rc = 30; signal error; end
  129.         end
  130.     signal cleanup
  131.     end
  132.  
  133. /*
  134. ** Update NewFiles.txt, delete it first if there's a old one there already
  135. */
  136.  
  137. if (delnf) & (exists(bbsdata.BBSPATH || 'Newfiles.txt')) then do
  138.     address(command)
  139.     'Delete "'bbsdata.BBSPATH || 'Newfiles.txt" QUIET'
  140.     if (rc ~= 0) then do; myerr = 'Could not update Newfiles.txt.'; rc = 30; signal error; end
  141.     address(bbsread)
  142.     end
  143.  
  144. if (exists(bbsdata.BBSPATH || 'Newfiles.txt')) then openar = open(ar, bbsdata.BBSPATH || 'Newfiles.txt', 'A')
  145. else openar = open(ar, bbsdata.BBSPATH || 'Newfiles.txt', 'W')
  146.  
  147. if ~(openar) then do; myerr = 'Could not open Newfiles.txt for writing.'; rc = 30; signal error; end
  148.  
  149. /*
  150. ** Process the RECENT message
  151. */
  152.  
  153. do until curline > text.TEXT.COUNT
  154.     aline = text.TEXT.curline
  155.  
  156.     if (left(aline, 1) = '|') then signal writestats
  157.     if (aline = 'Message of the day:') then signal writemotd
  158.  
  159.     if (aline ~= '') then do
  160.         delfile = 0; drop found. filetags.
  161.  
  162.         if (args.DONTADD) then addfile = 0; else addfile = 1
  163.  
  164.         farea = word(aline, 2)
  165.  
  166.         if (addfile) & (openexcl) then do i = 1 to excldir.count
  167.             if (index(excldir.i, '/') > 0) & (farea = excldir.i) then addfile = 0
  168.             else if left(farea, length(excldir.i)) = excldir.i then addfile = 0
  169.             end
  170.  
  171.         if (addfile) then do
  172.             fname = word(aline, 1)
  173.             fdesc = right(aline, length(aline) - 35)
  174.  
  175.             fsize = right(left(aline, 34), 5)
  176.             if (right(fsize, 1) = 'M') then mega = 1
  177.             else mega = 0
  178.             fsize = compress(fsize, 'KM .')
  179.  
  180.             if ~(datatype(fsize, 'W')) then fsize = 0
  181.             fsize = fsize * 1024
  182.             if (mega) then fsize = trunc((fsize * 1024) / 10)
  183.  
  184.             /*
  185.             ** Because of a problem in bbsread.library, CHECKDUPES is
  186.             ** currently disabled
  187.  
  188.             if (args.CHECKDUPES) then do
  189.                 'SEARCHBRFILE BBSNAME "'args.SYSTEM'" FAREANAME "'farea'" SEARCH "'fname'" NAME STEM 'found
  190.                 if (rc = 6) then drop BBSREAD.LASTERROR
  191.                 else if (rc ~= 0) then signal error
  192.                 else if (result > 0) then do i = 1 to found.FILE.1.COUNT
  193.                     'READBRFILE BBSNAME "'args.SYSTEM'" FAREANAME "'farea'" FILENR 'found.FILE.1.i' TAGSSTEM 'filetags
  194.                     if (rc ~= 0) then signal error
  195.                     else if (filetags.DESCRIPTION.1 ~= fdesc) & (fsize > filetags.SIZE + 1023 | fsize < filetags.SIZE - 1024) then do
  196.                         'WRITEBRFILE BBSNAME "'args.SYSTEM'" FAREANAME "'farea'" UPDATEFILENR 'found.FILE.1.1' DELETEFILE'
  197.                         if (rc ~= 0) then signal error
  198.                         delfile = 1
  199.                         end
  200.                     if (delfile = 0) then addfile = 0
  201.                     end
  202.                 end
  203.  
  204.             **
  205.             */
  206.             end
  207.  
  208.         if (addfile) & (fdesc ~= '') then do
  209.             'CONFIGFAREA "'args.SYSTEM'" "'farea'"'
  210.             if (rc ~= 0) then signal error
  211.  
  212.             drop brfile.
  213.             brfile.NAME = fname
  214.             brfile.SIZE = fsize
  215.             brfile.DATE = head.CREATIONDATE
  216.             brfile.DESCRIPTION.COUNT = 1
  217.             brfile.DESCRIPTION.1 = strip(fdesc)
  218.  
  219.             'WRITEBRFILE "'args.SYSTEM'" "'farea'" STEM 'brfile
  220.             if (rc ~= 0) then signal error
  221.             end
  222.  
  223.         if (writeln(ar, aline) = 0) then do; myerr = 'Failed to add data to Newfiles.txt.'; rc = 30; signal error; end
  224.         end
  225.     curline = curline + 1
  226.     end
  227.  
  228. signal amifini
  229.  
  230. /*
  231. ** Write statistics from AmiNet
  232. */
  233.  
  234. writestats:
  235.  
  236. if (args.NOSTATS) then signal amifini
  237.  
  238. logcount = logcount + 1; newmsg.text.logcount = '*AmiNet* *Statistics*'
  239. logcount = logcount + 1; newmsg.text.logcount = ''
  240.  
  241. do i = curline to text.TEXT.COUNT
  242.     aline = text.TEXT.i
  243.     if (aline = 'Message of the day:') then do
  244.         curline = i
  245.         signal writemotd
  246.         end
  247.     logcount = logcount + 1; newmsg.text.logcount = aline
  248.     end
  249. logcount = logcount + 1; newmsg.text.logcount = ''
  250.  
  251. signal amifini
  252.  
  253. /*
  254. ** Write AmiNet Message of the Day
  255. */
  256.  
  257. writemotd:
  258.  
  259. if (args.NOSTATS) then signal amifini
  260.  
  261. 'AMIGA2DATE SECONDS 'head.CREATIONDATE' STEM 'time
  262. if (rc ~= 0) then signal error
  263.  
  264. logcount = logcount + 1; newmsg.text.logcount = '*AmiNet* *Message* *of* *the* *Day*: 'time.MDAY'.'time.MONTH'.'time.YEAR
  265. logcount = logcount + 1; newmsg.text.logcount = ''
  266.  
  267. do i = curline to text.TEXT.COUNT
  268.     aline = text.TEXT.i
  269.     if (left(aline, 1) = '|') then do
  270.         curline = i
  271.         signal writestats
  272.         end
  273.     logcount = logcount + 1; newmsg.text.logcount = aline
  274.     end
  275. logcount = logcount + 1; newmsg.text.logcount = ''
  276.  
  277. /*
  278. ** Clean up and return
  279. */
  280.  
  281. amifini:
  282. call close(ar)
  283.  
  284. if (exists('C:Sort')) then do
  285.     address(command)
  286.     'C:Sort FROM 'bbsdata.BBSPATH'Newfiles.txt TO 'bbsdata.BBSPATH'Newfiles.txt COLSTART 20'
  287.     end
  288.  
  289. if logcount > 0 then call writemessage(args.SYSTEM, 'Information')
  290.  
  291. signal cleanup
  292.  
  293. /*
  294. ** Some error detection stuff
  295. */
  296.  
  297. error:
  298. syntax:
  299.  
  300. returned = rc
  301.  
  302. select
  303.     when symbol('BBSREAD.LASTERROR') = 'VAR' then say 'Line 'sigl' returned 'returned': 'BBSREAD.LASTERROR
  304.     when symbol('myerr') = 'VAR' then say 'Line 'sigl' returned 'returned': 'myerr
  305.     otherwise say 'Line 'sigl' returned 'returned': 'errortext(returned)
  306.     end
  307.  
  308. break_c:
  309. halt:
  310. cleanup:
  311.  
  312. /*
  313. ** Turn off copyback buffer
  314. */
  315.  
  316. address(bbsread)
  317. 'BUFMODE ENDCOPYBACK'
  318.  
  319. if (returned = 0) then do
  320.     lastadd = date('I') * 24 * 60 + time('M')
  321.     call setclip('SM_LastAdd', lastadd)
  322.     exit(0)
  323.     end
  324. else exit(returned)
  325.  
  326.  /****************************************************************************
  327. ************************** Write message to database **************************
  328.  ****************************************************************************/
  329.  
  330. writemessage: interpret 'procedure expose 'globals
  331.               parse arg system, conference
  332.  
  333. CDF_NOT_ON_BBS         = '00008000'x  /* This conference is not on the bbs. */
  334.  
  335. CDNT_INFO              = 4            /* This conference is an information conference */
  336.  
  337. /*
  338. ** See if the conference the msg will be written to exists
  339. */
  340.  
  341. address(bbsread)
  342. 'GETCONFLIST BBSNAME "'system'" STEM 'conflist
  343. if (rc ~= 0) then signal error
  344.  
  345. do n = 1 to conflist.COUNT + 1 while upper(conference) ~= upper(conflist.n)
  346.     if (n = conflist.COUNT + 1) then do
  347.         /* Create the new conference */
  348.         'CONFIGCONF "'system'" "'conference'" SET 'c2x(CDF_NOT_ON_BBS)' CONFNETTYPE 'CDNT_INFO
  349.         if (rc ~= 0) then signal error
  350.         conflist.n = toconf
  351.         conflist.COUNT = conflist.COUNT + 1
  352.         end
  353.     end
  354.  
  355. /*
  356. ** If Show own messages isn't activated in conference mark then don't
  357. ** mark message as unread.
  358. */
  359.  
  360. 'GETCONFDATA "'system'" "'conference'" STEM 'confdata
  361. if (rc ~= 0) then signal error
  362.  
  363. if (confdata.CONFTYPE ~= CDNT_MAILFOLDER) then do
  364.     'CONFIGCONF "'system'" "'conference'" SET 'c2x(CDF_NOT_ON_BBS)' CONFNETTYPE 'CDNT_INFO
  365.     if (rc ~= 0) then signal error        
  366.     end
  367.  
  368. /*
  369. ** Write the message
  370. */
  371.  
  372. newmsg.FROMNAME   = head.FROMNAME
  373. newmsg.SUBJECT    = 'Aminet log message'
  374. newmsg.TEXT.COUNT = logcount
  375.  
  376. 'WRITEBRMESSAGE "'system'" "'conference'" STEM 'newmsg
  377. if (rc ~= 0) then signal error
  378.  
  379. return(0)
  380.